<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:s="http://jboss.com/products/seam/taglib" 
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html" 
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:rich="http://richfaces.org/rich" 
	xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
	xmlns:tt="https://code.google.com/p/rad-framework" 
	template="#{theme.layout}">

	<ui:param name="title" value="#{messages['SearchResults']}" />
	<ui:define name="crumbs" />

	<ui:define name="left">
		<a4j:form id="sidebarForm">
			<rich:panel style="width:192px" styleClass="rich-panel-action">
			</rich:panel>
			<rich:spacer width="1" height="15" />
			<ui:include src="/themes/default/includes/recent.xhtml" />
		</a4j:form>
	</ui:define>

	<ui:define name="center">

		<tt:toggle-panel id="searchTP" label="#{messages['Search']}"
			rendered="true" switchType="client" opened="true">

			<h:form id="searchForm">
				<h:panelGrid columns="6" cellpadding="2" cellspacing="2">

					<h:panelGrid columns="2" cellpadding="2" cellspacing="2">
						<h:outputLabel value="#{messages['Terms']}:"
							styleClass="rad-framework-form-label" />

						<h:inputText id="searchText" value="#{searchAction.searchPattern}"
							styleClass="rad-framework-form-input-field" size="15" maxlength="1000">
						</h:inputText>
					</h:panelGrid>

					<ui:remove>
					<h:panelGrid columns="2" cellpadding="2" cellspacing="2">
						<h:outputLabel value="#{messages['In']}:"
							styleClass="rad-framework-form-label" />
						<h:selectOneMenu value="#{searchAction.pageSize}">
							<s:selectItems value="#{rad.framework.entityPersistenceContextMap.entityNames}"
								var="se" label="#{se}"
								noSelectionLabel="#{messages['All']}"/>
						</h:selectOneMenu>
					</h:panelGrid>
					</ui:remove>

					<h:panelGrid columns="2" cellpadding="2" cellspacing="2">
						<h:outputLabel value="#{messages['Results']}:"
							styleClass="rad-framework-form-label" />

						<h:selectOneMenu value="#{searchAction.pageSize}">
							<f:selectItem itemLabel="5" itemValue="5" />
							<f:selectItem itemLabel="15" itemValue="15" />
							<f:selectItem itemLabel="25" itemValue="25" />
							<f:selectItem itemLabel="50" itemValue="50" />
						</h:selectOneMenu>
					</h:panelGrid>

					<h:commandLink id="searchButton" styleClass="rad-framework-button-content"
						action="/jsf/search.xhtml">
						<f:param name="currentPage" value="1" />
						<span>
							<h:outputText value="#{messages['Find']}" />
						</span>
						<s:defaultAction />
					</h:commandLink>

				</h:panelGrid>
			</h:form>
		</tt:toggle-panel>
		
		<rich:spacer width="1" height="15" />

		<tt:toggle-panel id="resultsTP" label="#{messages['Results']}"
			rendered="true" switchType="client" opened="true">

			<h:panelGroup cellspacing="8">
				<span style="font-size: 110%;text-align:right;">
					<ui:repeat value="#{searchAction.pages}" var="page">
						<s:link value="#{page.text}" view="/jsf/search.xhtml">
							<f:param name="currentPage" value="#{page.currentPage}" />
						</s:link>
					</ui:repeat>
				</span>
			</h:panelGroup>

			<br />
			<rich:spacer width="1" height="15" />

			<rich:dataTable value="#{searchAction.searchResults}"
				var="result" onRowMouseOver="this.style.backgroundColor='#F1F1F1'"
				onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'"
				width="100%">
				<h:column>
					<div>
						<h:graphicImage value="/themes/default/images/iconLeaf.gif" />
						<rich:spacer width="10" height="0" />

						<span style="font-size: 145%">
							<s:link view="#{result.url}" propagation="none" value="#{result.title}">
								<f:param name="id" value="#{result.id}" />
							</s:link>
						</span>

						<br />
						<s:formattedText value="#{result.summary}" />
					</div>
				</h:column>
			</rich:dataTable>

			<f:subview id="noresults" rendered="#{searchAction.numberOfResults == 0}">
				<h2>No Results Found for #{searchAction.searchPattern}!</h2>
			</f:subview>

			<f:subview id="setup_error" rendered="#{searchAction.numberOfResults == -1}">
				<h2>Entities Incorrectly setup</h2>
				search expected the POJO entities to meet a minimum set of
				requirements.
				<ul>
					<li>
						All Entities must have at least one field named title.
						<br />
						The Annotation should look something like this (above the get
						method for the property):
						<br />
						<i>@Field(name ="title", store = Store.YES, index =
							Index.TOKENIZED)</i>
					</li>
					<li>
						The "title" and "description" field should both have store =
						STORE.YES
						in their annotation
   			</li>
				</ul>

				If you have made these changes and are still getting this error, you
				need to reindex the data.
				<br />
				Error occured while processing #{searchAction.classInError} Class
			</f:subview>

			<br />

			<span style="font-size: 110%">
				<ui:repeat value="#{searchAction.pages}" var="page">
					<s:link value="#{page.text}" view="/jsf/search.xhtml">
						<f:param name="currentPage" value="#{page.currentPage}" />
					</s:link>
				</ui:repeat>
			</span>
			
		</tt:toggle-panel>

	</ui:define>

</ui:composition>